package com.dormms.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dormms.bean.Dorm;
import com.dormms.bean.GoodRepair;
import com.dormms.dao.DormDao;
import com.dormms.dao.DormLocationDao;
import com.dormms.dao.GoodInfoDao;
import com.dormms.dao.GoodReapirDao;
import com.dormms.dao.StaffInfoDao;
import com.dormms.dao.StuInfoDao;
import com.dormms.dto.GoodRepairInfo;
import com.dormms.dto.GoodRepairShowInfo;
import com.dormms.service.GoodRepairService;

@Service
public class GoodRepairServiceImpl implements GoodRepairService {
	@Autowired
	private GoodReapirDao goodReapirDao;
	@Autowired
	private DormDao dormDao;
	@Autowired
	private GoodInfoDao goodInfoDao;
	@Autowired
	private StuInfoDao stuInfoDao;
	@Autowired
	private DormLocationDao dormLocationDao;
	@Autowired
	private StaffInfoDao staffInfoDao;

	public Integer insertGoodReapir(GoodRepair goodRepair) {
		// TODO Auto-generated method stub
		Integer dormId = dormDao.queryDormIdByStuId(goodRepair.getStuId());
		goodRepair.setDormId(dormId);
		goodRepair.setRequestTime(new Date());
		goodRepair.setRepairStatus(1);
		return goodReapirDao.insertGoodRepair(goodRepair);
	}

	public Integer updateGoodRepairByStu(GoodRepair goodRepair) {
		// TODO Auto-generated method stub
		return goodReapirDao.updateGoodRepaiByStu(goodRepair);
	}

	public List<GoodRepairShowInfo> getGoodRepairShowInfoByStu(GoodRepair goodRepair) {
		// TODO Auto-generated method stub
		return goodReapirDao.getGoodRepairShowInfoByStu(goodRepair);
	}

	public GoodRepairInfo getGoodRepairInfo(Integer goodRepairId) {
		// TODO Auto-generated method stub
		GoodRepairInfo goodRepairInfo = new GoodRepairInfo();
		GoodRepair goodRepair = goodReapirDao.getGoodRepair(goodRepairId);
		goodRepairInfo.setGoodRepair(goodRepair);
		Dorm dorm = dormDao.queryDormByDormId(goodRepair.getDormId());
		goodRepairInfo.setDorm(dorm);
		goodRepairInfo.setDormLocation(dormLocationDao.queryDormLocationByDormLocationId(dorm.getDormLocationId()));
		goodRepairInfo.setGoodInfo(goodInfoDao.queryGoodInfoByGoodId(goodRepair.getGoodId()));
		goodRepairInfo.setStaffInfo(staffInfoDao.queryStaffInfoByStaffId(goodRepair.getStaffId()));
		goodRepairInfo.setStuInfo(stuInfoDao.queryStuInfoByStuId(goodRepair.getStuId()));
		return goodRepairInfo;
	}

	public List<GoodRepairShowInfo> getGoodRepairShowInfoByStaff(GoodRepair goodRepair) {
		// TODO Auto-generated method stub
		return goodReapirDao.getGoodRepairShowInfoByStaff(goodRepair);
	}

	public Integer updateGoodRepairStatusByStaff(GoodRepair goodRepair) {
		// TODO Auto-generated method stub
		return goodReapirDao.updateGoodRepairStatusByStaff(goodRepair);
	}

	public Integer updateGoodRepairByStaff(GoodRepair goodRepair) {
		// TODO Auto-generated method stub
		return goodReapirDao.updateGoodRepairByStaff(goodRepair);
	}

	public Integer deleteGoodRepairInfo(Integer goodRepairId) {
		// TODO Auto-generated method stub
		return goodReapirDao.deleteGoodRepairInfo(goodRepairId);
	}
}
